Previous Book Contents Book Index Next

Inside Macintosh: AppleScript Scripting Additions Guide /
Chapter 2 - Scripting Addition Commands / Command Definitions
/


Open for Access

The Open for Access command opens access to a file for reading or writing using the Read and Write commands. Opening a file for reading and writing is not the same as opening it with the Open command. The file is open only in the sense that AppleScript has access to it for reading and writing data; it doesn't appear in one of the target application's windows, and it doesn't even have to be one of the target application's files.

Open for Access is one of several commands provided by the Read/Write Commands scripting addition. For more information about these commands, see "Using Read/Write Commands,".

SYNTAX
open for access referenceToFile [ write permission Boolean ]
PARAMETERS
referenceToFile
A reference of the form file nameString or alias nameString. If you specify an alias, the file must already exist, because AppleScript must locate the file before running the script. If you specify a file that doesn't exist using the form file nameString, Open for Access creates a TeachText document of that name at the specified location and opens it for access.
Class: Reference
Boolean
An expression that evaluates to true or false. If it evaluates to true, AppleScript opens the file with read and write permission. If it evaluates to false or if this parameter is omitted entirely, AppleScript opens the file with read permission only. Note that the phrase with write permission is equivalent to the phrase write permission true; similarly, without write permission is equivalent to write permission false.
Class: Boolean
RESULT
File reference number.

EXAMPLE
This example opens the file named To Donald in the specified location for subsequent access with the Read command.

tell application "Scriptable Text Editor"   open for access file "Hard Disk:Letters:To Donald"end tell
The next example opens the file associated with the file reference number for subsequent access with the Read or Write command.

tell application "Scriptable Text Editor"   open for access alias "Hard Disk:Aliases:To Donald" ¬ 
      with write permission
end tell
NOTES
To specify the name (nameString) of a file, use a string of the form "Disk:Folder1:
Folder2:...:Filename"
as described in Chapter 5, "Objects and References,"
of the AppleScript Language Guide. If you specify only the name of the file (Filename) instead of its entire pathname, AppleScript attempts to find the file in the current directory.

ERRORS
Error
number
Error message
-35Disk <name> wasn't found.
-37Bad name for file.
-42Too many files open.
-43File <name> wasn't found.
-44Disk <name> is write protected.
-49File <name> is already open.
-50Parameter error.

Previous Book Contents Book Index Next

© Apple Computer, Inc.
18 DEC 1996